<?php

/**
 * SSO通知接收接口
 * File Name：ApiController.php
 * File Encoding：UTF-8
 * File New Time：2014-10-22 11:37:41
 * Author：水平凡
 * Mailbox：admin@abc3210.com
 */
class ApiController extends SSOServer {

    public function init() {
        $code = $_GET['code'];
        parse_str(Encrypt::authcode($code, 'DECODE', Yii::app()->params['ssoconfig']['client_key']), $get);
        $post = Encrypt::authcode($_POST['code'], 'DECODE', Yii::app()->params['ssoconfig']['client_key']);
        if (!empty($post)) {
            $post = unserialize($post);
        }
        if (in_array($get['action'], array('demo', 'synlogin', 'synlogout'))) {
            echo $this->$get['action']($get, $post);
            exit;
        } else {
            exit('0');
        }
    }

    //测试接口
    public function demo($get, $post) {
        return 1;
    }

    //同步登录
    public function synlogin($get, $post) {
        $uid = $get['uid'];
        if (empty($uid)) {
            return 0;
        }
        $info = MembersModel::model()->findByPk($uid);
        if (empty($info)) {
            return 0;
        }
        Yii::app()->user->registerLogin($info);
        return 1;
    }

    //同步退出
    public function synlogout($get, $post) {
        Yii::app()->user->logout();
        return 1;
    }

}
